package org.idea.spring.framework.event;

import lombok.SneakyThrows;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.support.GenericApplicationContext;

/**
 * 面向接口的操作案例
 *
 * @Author linhao
 * @Date created in 4:20 下午 2021/5/23
 */
public class SpringEventDemo {

    public static void main(String[] args) {
        GenericApplicationContext context = new GenericApplicationContext();
        context.addApplicationListener(new ApplicationListener<ApplicationEvent>() {
            @SneakyThrows
            @Override
            public void onApplicationEvent(ApplicationEvent event) {
                System.out.println("接收到事件数据：" + event);
                //这种事件处理是属于同步操作
                Thread.sleep(1000);
            }
        });
        context.refresh();
        System.out.println("===refresh");
        context.start();
        System.out.println("===start");
        context.close();
        System.out.println("===close");
    }
}
